//
//  dPickerViewController.m
//  Surveyer
//
//  Created by Qikun Guo on 13-7-30.
//  Copyright (c) 2013年 Tim. All rights reserved.
//

#import "dPickerViewController.h"
#import "TypeRedirector.h"

@interface dPickerViewController ()

@end

@implementation dPickerViewController
@synthesize picker, titleLabel, currentItem, currentResult;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    titleLabel.text = self.currentItem.title;
    NSMutableArray *temp = [[NSMutableArray alloc] init];
    if (currentItem.value1)
        [temp addObject:currentItem.value1];
    if (currentItem.value2)
        [temp addObject:currentItem.value2];
    if (currentItem.value3)
        [temp addObject:currentItem.value3];
    if (currentItem.value4)
        [temp addObject:currentItem.value4];
    array = temp;
    [picker selectedRowInComponent:currentResult.text.intValue];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return array.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [array objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.editCount ++;
    if (!currentResult)
        currentResult = [[SurveyerStore defaultStore] createResultWithSurveyItem:currentItem];
    currentResult.text = [NSString stringWithFormat:@"%d", row];
    [self.delegate currentItemCompleted:self];
}

@end
